```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TCP与UDP协议对比 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        .feature-icon {
            font-size: 2.5rem;
            margin-bottom: 1rem;
        }
        .drop-cap::first-letter {
            float: left;
            font-size: 4rem;
            line-height: 0.8;
            margin: 0.15em 0.1em 0 0;
            color: #2a5298;
            font-weight: 700;
        }
        .mermaid {
            background-color: white;
            border-radius: 0.5rem;
            padding: 1.5rem;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6">TCP与UDP协议深度解析</h1>
            <p class="text-xl md:text-2xl mb-8 max-w-3xl mx-auto">探索网络通信中两大核心协议的关键差异与应用场景</p>
            <div class="flex justify-center space-x-4">
                <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full flex items-center">
                    <i class="fas fa-network-wired mr-2"></i> 网络协议
                </span>
                <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full flex items-center">
                    <i class="fas fa-exchange-alt mr-2"></i> 数据传输
                </span>
            </div>
        </div>
    </section>

    <!-- Introduction Section -->
    <section class="py-16 px-4 md:px-0 bg-gray-50">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-8 md:mb-0 md:pr-12">
                    <h2 class="text-3xl font-bold mb-6 text-gray-800">协议概述</h2>
                    <p class="text-lg text-gray-700 mb-6 drop-cap">在网络通信的世界中，TCP和UDP作为传输层的两大核心协议，各自有着独特的设计哲学和应用场景。理解它们的差异对于构建高效、可靠的网络应用至关重要。</p>
                    <p class="text-gray-600">本文将从连接性、可靠性、传输速度、数据包结构和应用场景五个维度，深入剖析这两种协议的特性与差异。</p>
                </div>
                <div class="md:w-1/2">
                    <div class="mermaid">
                        graph TD
                            A[传输层协议] --> B(TCP)
                            A --> C(UDP)
                            B --> D[面向连接]
                            B --> E[可靠传输]
                            B --> F[速度较慢]
                            C --> G[无连接]
                            C --> H[不可靠传输]
                            C --> I[速度快]
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Comparison Section -->
    <section class="py-16 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl">
            <h2 class="text-3xl font-bold mb-12 text-center text-gray-800">关键特性对比</h2>
            
            <!-- Connection -->
            <div class="grid md:grid-cols-2 gap-8 mb-16">
                <div class="bg-white p-8 rounded-lg shadow-md card-hover border-l-4 border-blue-500">
                    <h3 class="text-2xl font-bold mb-4 text-blue-600 flex items-center">
                        <i class="fas fa-link mr-3"></i> 连接性 - TCP
                    </h3>
                    <p class="text-gray-700 mb-4">TCP是一个<strong>面向连接</strong>的协议。在数据传输之前，TCP必须通过"三次握手"过程建立连接，并在数据传输结束后通过"四次挥手"来关闭连接。</p>
                    <ul class="space-y-2 text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mr-2 mt-1"></i>
                            <span>确保数据的有序传输</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mr-2 mt-1"></i>
                            <span>提供端到端的可靠通信</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-times-circle text-red-500 mr-2 mt-1"></i>
                            <span>连接建立过程增加开销</span>
                        </li>
                    </ul>
                </div>
                <div class="bg-white p-8 rounded-lg shadow-md card-hover border-l-4 border-purple-500">
                    <h3 class="text-2xl font-bold mb-4 text-purple-600 flex items-center">
                        <i class="fas fa-unlink mr-3"></i> 连接性 - UDP
                    </h3>
                    <p class="text-gray-700 mb-4">UDP是一个<strong>无连接</strong>的协议。它不需要在传输数据之前建立连接，也没有关闭连接的过程。</p>
                    <ul class="space-y-2 text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mr-2 mt-1"></i>
                            <span>传输过程简单快速</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mr-2 mt-1"></i>
                            <span>没有连接管理的开销</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-times-circle text-red-500 mr-2 mt-1"></i>
                            <span>不保证数据的有序到达</span>
                        </li>
                    </ul>
                </div>
            </div>

            <!-- Reliability -->
            <div class="grid md:grid-cols-2 gap-8 mb-16">
                <div class="bg-white p-8 rounded-lg shadow-md card-hover border-l-4 border-blue-500">
                    <h3 class="text-2xl font-bold mb-4 text-blue-600 flex items-center">
                        <i class="fas fa-shield-alt mr-3"></i> 可靠性 - TCP
                    </h3>
                    <p class="text-gray-700 mb-4">TCP提供<strong>可靠的</strong>数据传输，通过多种机制确保数据的完整性和顺序。</p>
                    <div class="grid grid-cols-2 gap-4">
                        <div class="bg-blue-50 p-3 rounded">
                            <h4 class="font-semibold text-blue-700 mb-1">确认应答</h4>
                            <p class="text-sm text-gray-600">接收方发送ACK确认收到的数据包</p>
                        </div>
                        <div class="bg-blue-50 p-3 rounded">
                            <h4 class="font-semibold text-blue-700 mb-1">重传机制</h4>
                            <p class="text-sm text-gray-600">丢失或损坏的数据包会重新发送</p>
                        </div>
                        <div class="bg-blue-50 p-3 rounded">
                            <h4 class="font-semibold text-blue-700 mb-1">流量控制</h4>
                            <p class="text-sm text-gray-600">调节发送速率避免接收方过载</p>
                        </div>
                        <div class="bg-blue-50 p-3 rounded">
                            <h4 class="font-semibold text-blue-700 mb-1">拥塞控制</h4>
                            <p class="text-sm text-gray-600">动态调整传输速率避免网络拥堵</p>
                        </div>
                    </div>
                </div>
                <div class="bg-white p-8 rounded-lg shadow-md card-hover border-l-4 border-purple-500">
                    <h3 class="text-2xl font-bold mb-4 text-purple-600 flex items-center">
                        <i class="fas fa-bolt mr-3"></i> 可靠性 - UDP
                    </h3>
                    <p class="text-gray-700 mb-4">UDP是一个<strong>不保证可靠性</strong>的协议，数据传输过程中可能会出现丢包、重复或乱序。</p>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="bg-purple-100 rounded-full p-2 mr-3">
                                <i class="fas fa-exclamation-triangle text-purple-600"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-purple-700">无确认机制</h4>
                                <p class="text-sm text-gray-600">发送方不知道数据是否到达</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="bg-purple-100 rounded-full p-2 mr-3">
                                <i class="fas fa-random text-purple-600"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-purple-700">无序到达</h4>
                                <p class="text-sm text-gray-600">数据包可能以发送顺序不同的顺序到达</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="bg-purple-100 rounded-full p-2 mr-3">
                                <i class="fas fa-tachometer-alt text-purple-600"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-purple-700">无流量控制</h4>
                                <p class="text-sm text-gray-600">可能因发送过快导致丢包</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Speed -->
            <div class="bg-white rounded-lg shadow-md overflow-hidden mb-16">
                <div class="p-8">
                    <h3 class="text-2xl font-bold mb-6 text-gray-800 text-center">传输速度对比</h3>
                    <div class="flex flex-col md:flex-row justify-between items-center">
                        <div class="md:w-1/2 mb-8 md:mb-0 md:pr-8">
                            <div class="h-8 bg-gradient-to-r from-blue-500 to-blue-300 rounded-full mb-2">
                                <div class="h-full w-3/4 bg-white bg-opacity-30 rounded-full flex items-center justify-end pr-2 text-white text-xs font-bold">75%</div>
                            </div>
                            <h4 class="text-lg font-semibold text-blue-600">TCP</h4>
                            <p class="text-gray-600">由于连接建立、确认应答等机制，传输速度相对较慢</p>
                        </div>
                        <div class="md:w-1/2">
                            <div class="h-8 bg-gradient-to-r from-purple-500 to-purple-300 rounded-full mb-2">
                                <div class="h-full w-full bg-white bg-opacity-30 rounded-full flex items-center justify-end pr-2 text-white text-xs font-bold">100%</div>
                            </div>
                            <h4 class="text-lg font-semibold text-purple-600">UDP</h4>
                            <p class="text-gray-600">无连接、无确认机制，传输速度更快</p>
                        </div>
                    </div>
                </div>
                <div class="bg-gray-50 px-8 py-4 border-t border-gray-200">
                    <p class="text-sm text-gray-500 text-center"><i class="fas fa-info-circle mr-1"></i> 速度对比基于相同网络条件下的理论值</p>
                </div>
            </div>

            <!-- Packet Structure -->
            <div class="grid md:grid-cols-2 gap-8 mb-16">
                <div class="bg-white p-8 rounded-lg shadow-md card-hover">
                    <h3 class="text-2xl font-bold mb-6 text-center text-gray-800">TCP数据包结构</h3>
                    <div class="bg-gray-100 rounded p-4">
                        <div class="border-b border-gray-300 py-2 px-3 bg-blue-50">
                            <span class="font-mono text-sm text-blue-700">源端口 | 目标端口 | 序列号 | 确认号</span>
                        </div>
                        <div class="border-b border-gray-300 py-2 px-3">
                            <span class="font-mono text-sm text-gray-700">数据偏移 | 保留 | 控制位 | 窗口大小</span>
                        </div>
                        <div class="border-b border-gray-300 py-2 px-3 bg-blue-50">
                            <span class="font-mono text-sm text-blue-700">校验和 | 紧急指针</span>
                        </div>
                        <div class="py-2 px-3 bg-gray-200">
                            <span class="font-mono text-sm text-gray-800">选项(可选) | 填充</span>
                        </div>
                        <div class="mt-2 py-2 px-3 bg-white border border-gray-300 rounded">
                            <span class="font-mono text-sm text-gray-900">数据部分</span>
                        </div>
                    </div>
                    <p class="mt-4 text-sm text-gray-600">TCP头部通常为20字节(无选项)，包含确保可靠传输所需的所有控制信息。</p>
                </div>
                <div class="bg-white p-8 rounded-lg shadow-md card-hover">
                    <h3 class="text-2xl font-bold mb-6 text-center text-gray-800">UDP数据包结构</h3>
                    <div class="bg-gray-100 rounded p-4">
                        <div class="border-b border-gray-300 py-2 px-3 bg-purple-50">
                            <span class="font-mono text-sm text-purple-700">源端口 | 目标端口</span>
                        </div>
                        <div class="border-b border-gray-300 py-2 px-3">
                            <span class="font-mono text-sm text-gray-700">长度 | 校验和</span>
                        </div>
                        <div class="mt-2 py-2 px-3 bg-white border border-gray-300 rounded">
                            <span class="font-mono text-sm text-gray-900">数据部分</span>
                        </div>
                    </div>
                    <p class="mt-4 text-sm text-gray-600">UDP头部固定为8字节，结构简单，开销小，适合需要高效传输的场景。</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Application Scenarios -->
    <section class="py-16 px-4 md:px-0 bg-gray-50">
        <div class="container mx-auto max-w-5xl">
            <h2 class="text-3xl font-bold mb-12 text-center text-gray-800">典型应用场景</h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white p-8 rounded-lg shadow-md">
                    <div class="flex items-center mb-6">
                        <div class="bg-blue-100 p-3 rounded-full mr-4">
                            <i class="fas fa-lock text-blue-600 text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-bold text-blue-600">TCP 应用场景</h3>
                    </div>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="bg-blue-50 rounded-full p-2 mr-3">
                                <i class="fas fa-globe text-blue-500"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-gray-800">网页浏览 (HTTP/HTTPS)</h4>
                                <p class="text-sm text-gray-600">确保网页内容完整加载，顺序正确</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="bg-blue-50 rounded-full p-2 mr-3">
                                <i class="fas fa-envelope text-blue-500"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-gray-800">电子邮件 (SMTP/IMAP/POP3)</h4>
                                <p class="text-sm text-gray-600">保证邮件内容不丢失、不损坏</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="bg-blue-50 rounded-full p-2 mr-3">
                                <i class="fas fa-file-download text-blue-500"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-gray-800">文件传输 (FTP/SFTP)</h4>
                                <p class="text-sm text-gray-600">确保文件传输的完整性和准确性</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="bg-blue-50 rounded-full p-2 mr-3">
                                <i class="fas fa-database text-blue-500"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-gray-800">数据库连接</h4>
                                <p class="text-sm text-gray-600">保证数据查询和更新的可靠性</p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="bg-white p-8 rounded-lg shadow-md">
                    <div class="flex items-center mb-6">
                        <div class="bg-purple-100 p-3 rounded-full mr-4">
                            <i class="fas fa-bolt text-purple-600 text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-bold text-purple-600">UDP 应用场景</h3>
                    </div>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="bg-purple-50 rounded-full p-2 mr-3">
                                <i class="fas fa-video text-purple-500"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-gray-800">实时视频流</h4>
                                <p class="text-sm text-gray-600">容忍少量丢包，优先保证实时性</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="bg-purple-50 rounded-full p-2 mr-3">
                                <i class="fas fa-phone-alt text-purple-500"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-gray-800">语音通信 (VoIP)</h4>
                                <p class="text-sm text-gray-600">低延迟比完美音频更重要</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="bg-purple-50 rounded-full p-2 mr-3">
                                <i class="fas fa-gamepad text-purple-500"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-gray-800">在线游戏</h4>
                                <p class="text-sm text-gray-600">快速传输玩家动作和状态更新</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="bg-purple-50 rounded-full p-2 mr-3">
                                <i class="fas fa-broadcast-tower text-purple-500"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-gray-800">DNS查询</h4>
                                <p class="text-sm text-gray-600">简单请求-响应模式，无需保持连接</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="mt-12 bg-white rounded-lg shadow-md overflow-hidden">
                <div class="p-8">
                    <h3 class="text-2xl font-bold mb-6 text-center text-gray-800">协议选择决策树</h3>
                    <div class="mermaid">
                        graph TD
                            A[需要传输数据] --> B{需要可靠性保证?}
                            B -->|是| C[选择TCP]
                            B -->|否| D{对延迟敏感?}
                            D -->|是| E[选择UDP]
                            D -->|否| F{数据量大?}
                            F -->|是| C
                            F -->|否| G{能容忍丢包?}
                            G -->|是| E
                            G -->|否| C
                    </div>
                </div>
                <div class="bg-gray-50 px-8 py-4 border-t border-gray-200">
                    <p class="text-sm text-gray-500 text-center"><i class="fas fa-lightbulb mr-1"></i> 根据应用需求选择合适的传输协议</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Summary Section -->
    <section class="py-16 px-4 md:px-0">
        <div class="container mx-auto max-w-3xl">
            <div class="bg-gradient-to-r from-blue-500 to-purple-600 rounded-xl p-8 text-white">
                <h2 class="text-2xl md:text-3xl font-bold mb-6">关键总结</h2>
                <div class="space-y-4">
                    <div class="flex items-start">
                        <div class="bg-white bg-opacity-20 rounded-full p-2 mr-4">
                            <i class="fas fa-balance-scale"></i>
                        </div>
                        <div>
                            <h3 class="font-semibold text-lg">可靠性与速度的权衡</h3>
                            <p class="opacity-90">TCP提供可靠传输但速度较慢，UDP速度快但不保证可靠性。根据应用需求做出合适选择。</p>
                        </div>
                    </div>
                    <div class="flex items-start">
                        <div class="bg-white bg-opacity-20 rounded-full p-2 mr-4">
                            <i class="fas fa-project-diagram"></i>
                        </div>
                        <div>
                            <h3 class="font-semibold text-lg">连接管理的差异</h3>
                            <p class="opacity-90">TCP需要建立和关闭连接，UDP直接发送数据包。连接管理是影响性能的关键因素。</p>
                        </div>
                    </div>
                    <div class="flex items-start">
                        <div class="bg-white bg-opacity-20 rounded-full p-2 mr-4">
                            <i class="fas fa-cogs"></i>
                        </div>
                        <div>
                            <h3 class="font-semibold text-lg">控制机制的不同</h3>
                            <p class="opacity-90">TCP具有流量控制、拥塞控制等复杂机制，UDP则将这些功能交给应用层处理。</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12 px-4">
        <div class="container mx-auto max-w-5xl">
            <div class="text-center">
                <h3 class="text-xl font-semibold text-white mb-2">技术小馆</h3>
                <p class="mb-6">探索技术的无限可能</p>
                <a href="http://www.yuque.com/jtostring" class="text-blue-400 hover:text-blue-300 transition duration-300">
                    <i class="fas fa-external-link-alt mr-1"></i> http://www.yuque.com/jtostring
                </a>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 添加简单的滚动动画
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```